<?php

namespace App\Models\Goods;

use App\Models\Goods\Cates;
use App\Models\Goods\GoodSpecs;
use App\Models\Goods\GoodsImages;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Str;

class Goods extends Model
{
    use SoftDeletes;
    protected $table = 'goods';

    protected $fillable = [
        'goods_name','goods_num','goods_cate_id','goods_img','goods_price','goods_original_price','goods_desc','goods_sales','sort','is_show','is_home','goods_market_price','goods_postage','stock'
    ];
    protected $datas = ['deleted_at'];

    public function imgs()
    {
        return $this->hasMany(GoodsImages::class,'goods_id','id');
    }

    public function cate()
    {
        return $this->hasOne(Cates::class,'id','goods_cate_id');
    }

    public function sepcs()
    {
        return $this->hasMany(GoodSpecs::class,'goods_id','id');
    }

    public function setGoodsCateIdAttribute($value)
    {
        return $this->attributes['goods_cate_id'] = Str::after($value,'/');
    }


}
